#include "StdAfx.h"
#include "Figure.h"


Figure::Figure(CRect rect)
    :enclosingRect(rect)
{
    penWidth = 1;
}


Figure::~Figure(void)
{
}

CRect Figure::GetBoundRect()
{
    return enclosingRect;
}

void Figure::Move( const CPoint& point, CPoint& previousPoint, const CRect& drawArea )
{
    CPoint deltaPoint(point - previousPoint);
    if (enclosingRect.left + deltaPoint.x > 0 && enclosingRect.right + deltaPoint.x < drawArea.right)
    {
        enclosingRect.left += deltaPoint.x;
        enclosingRect.right += deltaPoint.x;
        previousPoint.x = point.x;
    }
    if (enclosingRect.top + deltaPoint.y > 0 && enclosingRect.bottom + deltaPoint.y < drawArea.bottom )
    {
        enclosingRect.bottom += deltaPoint.y;
        enclosingRect.top += deltaPoint.y;
        previousPoint.y = point.y;
    }
}

CRect Figure::GetMoveRect(const CPoint& point, CPoint& previousPoint)
{
    CRect r(enclosingRect);
    CPoint deltaPoint(point - previousPoint);    
    r.left += deltaPoint.x;
    r.right += deltaPoint.x;
    r.bottom += deltaPoint.y;
    r.top += deltaPoint.y;


    return r;
}